import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/button_widget.dart';
import 'package:basic_widgets/image_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'model/my_team_list_data.dart';
import 'my_team_controller.dart';
class MyTeamPage extends GetView<MyTeamController> {
  const MyTeamPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: backAppbar(title: "我的团队"),
      body: Container(
        // color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
        child: Column(
          children: [
            Obx(() => teamWidget(
                title: '我管理的团队', type: 1, list: controller.managerList.value)),
            Divider(
              height: ScreenHelper.height(10),
              color: AppTheme.appBgColor,
            ),
            Obx(() => teamWidget(
                title: '我加入的团队', type: 2, list: controller.joinList.value)),
            Spacer(),
            // Expanded(child: bottomWidget())
          ],
        ),
      ),
    );
  }

  /// type 1 我管理的 2 我加入的
  Widget teamWidget(
      {required String title, required int type, required List list}) {
    return Container(
      color: Colors.white,
      child: Column(
        children: [
          norTitle(title: title),
          divider(),
          SizedBox(
            // height: ScreenHelper.height(220),
            child: list!.length == 0
                ? EmptyBox(title: "暂无数据")
                : ListView.separated(
                    shrinkWrap: true,
                    itemBuilder: (context, index) {
                      if (type == 1) {
                        ManageTeam managerItem = list[index];
                        return buidldTeamInfo(
                            title: managerItem.teamName!,
                            org: managerItem.hospName!,
                            tNo: managerItem.teamNo!,
                            type: type,
                            logo: managerItem.logoUrl ?? '');
                      } else {
                        JoinTeam joinItem = list[index];
                        return buidldTeamInfo(
                            title: joinItem.teamName!,
                            org: joinItem.teamName!,
                            tNo: joinItem.teamNo!,
                            type: type,
                            logo: joinItem.logoUrl ?? '');
                      }
                    },
                    separatorBuilder: (context, index) => divider(),
                    itemCount: list.length),
          ),
        ],
      ),
    );
  }

  Widget buidldTeamInfo(
      {required String logo,
      required String title,
      required String org,
      required int type,
      required String tNo}) {
    return GestureDetector(
      onTap: () {
        if (type == 1) {
          Get.toNamed(AppRoutes.teamMember, arguments: {"teamNo": tNo});
        } else if (type == 2) {
          Get.toNamed(AppRoutes.teamMember, arguments: {"teamNo": tNo});
        }
      },
      child: ListTile(
        contentPadding: EdgeInsets.zero,
        leading: circleImg(raduis: 10, width: 55, head: logo),
        isThreeLine: true,
        dense: false,
        title: Text(
          '${title}',
          style: TextStyle(fontSize: ScreenHelper.sp(16),color: AppTheme.dartTextColor),
        ),
        subtitle: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              "所属机构：${org}",
              style: TextStyle(fontSize: ScreenHelper.sp(14)),
            ),
            Text(
              "团队编号：${tNo}",
              style: TextStyle(fontSize: ScreenHelper.sp(14)),
            ),
          ],
        ),
      ),
    );
  }

  // 底部按钮
  Widget bottomWidget() {
    return SizedBox(
      child: Row(
        children: [
          Expanded(
            child: connerButton(
                onPressed: () {
                  Get.toNamed(AppRoutes.addteam);
                },
                textStr: "新建团队",
                bgColor: Colors.white,
                textColor: AppTheme.primyColor),
          ),
          SizedBox(
            width: ScreenHelper.width(10),
          ),
          Expanded(
            child: connerButton(
                onPressed: () {},
                textStr: "加入团队",
                bgColor: AppTheme.primyColor,
                textColor: Colors.white),
          )
        ],
      ),
    );
  }
}
